#pragma once
#include "base/function.hpp"
#include "base/noncopyable.h"

#include <string>

#include "sys/time.h"
namespace net_tools{
class Eventloop;
namespace base{
class Channel;
class Timer;
class Timeeverymap;
class Timeevery : noncopyable{
 public:
  Timeevery() = delete;
  Timeevery(func func,timeval begin_time,timeval time,int count,net_tools::Eventloop* eventloop,Timeeverymap* timeeverymap,const std::string& name);
  ~Timeevery();
  void Time_out();
  inline int Get_fd()const{return timerfd_;};
  inline Channel* Get_channel(){return channel_;};
  inline void Init_channel(Channel* channel){channel_ = channel;};
  void Clean_timeevery_right_thread();
  void Clean_timeevery();
  inline bool Is_takeplace()const{return is_takeplace_other_;};
 private:
  void Set_time();
  Timer*                timer_;
  int                   timerfd_;
  Channel*              channel_;
  func                  func_;
  timeval               begin_time_;
  timeval               time_;
  timeval               next_time_;
  int                   count_;
  net_tools::Eventloop* eventloop_;
  Timeeverymap*         timeeverymap_;
  std::string           time_job_name_;
  bool                  is_takeplace_other_;
};

} // namespace base
} // namespace net_tools